Fix depending on git repos with workspaces
authorAlex Crichton <alex@alexcrichton.com>
Sun, 31 Jul 2016 23:35:52 +0000 (16:35 -0700)
committerAlex Crichton <alex@alexcrichton.com>
Mon, 1 Aug 2016 00:06:35 +0000 (17:06 -0700)
When we're recursively walking over a git repository we can safely ignore any
workspace Cargo.toml files we find instead of generating an error.

src/cargo/ops/cargo_read_manifest.rs
tests/workspaces.rs

index 119466bd2baa99641f4291963766c37e6c2d2160..39028b798a2f583112e2f41a07e27a3ac54d6cbc 100644 (file)
@@ -119,9 +119,15 @@ fn read_nested_packages(path: &Path,
                         visited: &mut HashSet<PathBuf>) -> CargoResult<()> {
     if !visited.insert(path.to_path_buf()) { return Ok(()) }
 
-    let manifest = try!(find_project_manifest_exact(path, "Cargo.toml"));
+    let manifest_path = try!(find_project_manifest_exact(path, "Cargo.toml"));
+
+    let (manifest, nested) = try!(read_manifest(&manifest_path, source_id, config));
+    let manifest = match manifest {
+        EitherManifest::Real(manifest) => manifest,
+        EitherManifest::Virtual(..) => return Ok(()),
+    };
+    let pkg = Package::new(manifest, &manifest_path);
 
-    let (pkg, nested) = try!(read_package(&manifest, source_id, config));
     let pkg_id = pkg.package_id().clone();
     if !all_packages.contains_key(&pkg_id) {
         all_packages.insert(pkg_id, pkg);
index 3fad3b57ffac0fe4d6b89c38685fd504e96fabc0..dcec77ae3f4ef47a1857736bfd45ab67d3b55a57 100644 (file)
@@ -6,7 +6,7 @@ use std::io::{Read, Write};
 use std::fs::File;
 
 use cargotest::sleep_ms;
-use cargotest::support::{project, execs};
+use cargotest::support::{project, execs, git};
 use cargotest::support::registry::Package;
 use hamcrest::{assert_that, existing_file, existing_dir, is_not};
 
@@ -877,3 +877,36 @@ fn rebuild_please() {
     assert_that(p.cargo("run").cwd(p.root().join("bin")),
                 execs().with_status(101));
 }
+
+#[test]
+fn workspace_in_git() {
+    let git_project = git::new("dep1", |project| {
+        project
+            .file("Cargo.toml", r#"
+                [workspace]
+                members = ["foo"]
+            "#)
+            .file("foo/Cargo.toml", r#"
+                [package]
+                name = "foo"
+                version = "0.1.0"
+            "#)
+            .file("foo/src/lib.rs", "")
+    }).unwrap();
+    let p = project("foo")
+        .file("Cargo.toml", &format!(r#"
+            [package]
+            name = "lib"
+            version = "0.1.0"
+
+            [dependencies.foo]
+            git = '{}'
+        "#, git_project.url()))
+        .file("src/lib.rs", r#"
+            pub fn foo() -> u32 { 0 }
+        "#);
+    p.build();
+
+    assert_that(p.cargo("build"),
+                execs().with_status(0));
+}